@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">
    <style>
        .thumb {
            max-height: 60px;
        }
    </style>
@endsection
@section('content')
    <div class="admin-content">

        <div class="am-cf am-padding">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">订单详情</strong> /
                <small>Order Detail</small>
            </div>
        </div>

        @include('Admin.layouts._flash')

        <div class="am-g">
            <div class="am-u-sm-12">
                <div class="uc-box uc-main-box">
                    <div class="uc-content-box order-view-box">
                        <div class="box-hd">
                            <h1 class="title">订单详情

                            </h1>
                            <div class="more clearfix">
                                <h2 class="subtitle">订单号：
                                    <span class="tag tag-subsidy">{{$order->id}}</span>
                                </h2>

                            </div>
                        </div>
                        <div class="box-bd">
                            <div class="uc-order-item uc-order-item-finish">
                                <div class="order-detail">
                                    <div class="order-summary">

                                        <div class="order-status">
                                            {{order_status($order->status)}}

                                            <div style="float:right;margin-right:10px;">
                                                {{--配货--}}
                                                @if($order->status == 1)
                                                    <a class="am-btn am-btn-secondary am-radius"
                                                       id="picking">配餐</a>
                                                @endif

                                                @if($order->status == 2)
                                                    <a class="am-btn am-btn-secondary am-radius"
                                                       id="finish">交易完成</a>
                                                @endif
                                            </div>
                                        </div>

                                        <div class="order-progress">
                                            <ol class="progress-list clearfix">
                                                <li class="step step-first step-done">
                                                    <div class="progress"><span class="text">未处理</span></div>
                                                    <div class="info">{{ $order->created_at->format("Y年m月d日 H:i") }}</div>
                                                </li>
                                                <li class="step @if($order->status >= 2) step-done @endif">
                                                    <div class="progress"><span class="text">处理中</span></div>
                                                    <div class="info">{{ time_format("Y年m月d日 H:i", $order->pay_time) }}</div>
                                                </li>
                                                <li class="step @if($order->status == 3) step-active @endif step-last">
                                                    <div class="progress"><span class="text">交易成功</span></div>
                                                    <div class="info">{{ time_format("Y年m月d日 H:i", $order->finish_time) }}</div>
                                                </li>
                                            </ol>
                                        </div>
                                    </div>
                                    <table class="order-items-table">
                                        <tbody>

                                        @foreach($order->order_products as $order_product)
                                            <tr>
                                                <td class="col col-thumb">
                                                    <div class="figure figure-thumb">
                                                        <a target="_blank" href="//item.mi.com/1151400001.html">
                                                            <img src="{{$order_product->product->thumb}}" width="80"
                                                                 height="80" alt="">
                                                        </a>
                                                    </div>
                                                </td>
                                                <td class="col col-name">
                                                    <p class="name">
                                                        <a target="_blank"
                                                           href="//item.mi.com/1151400001.html">{{$order_product->product->name}}</a>
                                                    </p>
                                                </td>
                                                <td class="col col-price">
                                                    <p class="price">{{$order_product->product->price}}元
                                                        × {{$order_product->num}}</p>
                                                </td>
                                                <td class="col col-actions">
                                                </td>
                                            </tr>
                                        @endforeach


                                        </tbody>
                                    </table>
                                </div>
                                <div id="editAddr" class="order-detail-info">

                                    <h3>客户点餐信息</h3>
                                    <table class="info-table">
                                        <tbody>
                                        <tr>
                                            <th>房间号：</th>
                                            <td>{{$order->member->room->room}}</td>
                                        </tr>
                                        <tr>
                                            <th>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</th>
                                            <td>{{$order->member->username}}</td>
                                        </tr>
                                        {{--<tr>
                                            <th>联系电话：</th>
                                            <td><a href="tel:2211211">2121212</a></td>
                                        </tr>--}}
                                        </tbody>
                                    </table>
                                    <div class="actions">
                                    </div>

                                </div>
                                <div class="order-detail-total">
                                    <table class="total-table">
                                        <tbody>
                                        {{--<tr>
                                            <th>商品总价：</th>
                                            <td><span class="num">{{doubleval($order->total_price)}}</span>元</td>
                                        </tr>--}}
                                        <tr>
                                            <th>订单金额：</th>
                                            <td>
                                                <span class="num">{{doubleval($order->total_price + $order->express_money)}}</span>元
                                            </td>
                                        </tr>
                                        {{--<tr>
                                            <th class="total">实付金额：</th>
                                            <td class="total">
                                                <span class="num">{{doubleval($order->total_price + $order->express_money)}}</span>元
                                            </td>
                                        </tr>--}}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection


@section('js')
    <script>
        $(function () {
            //配餐
            $("#picking").click(function () {
                var id = "{{$order->id}}";
                $.ajax({
                    url: '/order/picking',
                    type: 'PATCH',
                    data: {id: id},
                    success: function (data) {
                        location.href = location.href;
                    }
                });
            });

            //修改发货信息
            $("#shipping").click(function () {
                var data = {
                    id: "{{$order->id}}",
                    status: $(this).data('status'),
                    express_code: $("#express_code").val(),
                    express_id: $("#express_id").val()
                }

                $.ajax({
                    url: '/xShop/order/shipping',
                    type: 'PATCH',
                    data: data,
                    success: function (data) {
                        location.href = location.href;
                    }
                });
                return false;
            })


            //交易成功
            $("#finish").click(function () {
                var data = {
                    id: "{{$order->id}}",
                }

                $.ajax({
                    url: '/order/finish',
                    type: 'PATCH',
                    data: data,
                    success: function (data) {
                        location.href = location.href;
                    }
                });
                return false;
            })

        })
    </script>
@endsection
